Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: declare that highspy._core supports free-threaded CPython #2063

Merged
merged 1 commit into from
Nov 27, 2024

Conversation

rgommers
Copy link
Contributor

This allows highspy to be imported in a free-threaded CPython interpreter (see PEP 703, https://py-free-threading.github.io/) without raising a warning and re-enabling the GIL. We've tested thread-safety of this extension module reasonably well in SciPy now, and everything seems fine on all tested platforms (Linux, macOS, Windows and x86-64/arm64).

The one-line change matches the Pybind11 example at https://py-free-threading.github.io/porting/#declaring-free-threaded-support.

This allows `highspy` to be imported in a free-threaded CPython
(see PEP 703) interpreter without raising a warning and re-enabling
the GIL. We've tested thread-safety of this extension module
reasonably well in SciPy now, and everything seems fine on all
tested platforms (Linux, macOS, Windows and x86-64/arm64).
Copy link
Member

@jajhall jajhall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be very welcome, but what's your view @galabovaa and @mathgeekcoder ?

@mathgeekcoder
Copy link
Contributor

If I'm understanding correctly, we're basically just turning off the GIL for everyone. I don't quite know the implications, but it sounds good to me - as long as we assume the user isn't wanting to try anything pathological. We make the same assumption for C++ users etc. anyhow.

I'm guessing if we make this change, we no longer need to disable the GIL in run and presolve via py::call_guard<py::gil_scoped_release>()?

@rgommers
Copy link
Contributor Author

If I'm understanding correctly, we're basically just turning off the GIL for everyone.

Almost. I'd phrase it more like "we avoid re-enabling the GIL for everyone globally when using a cp313t free-threaded interpreter". For any other Python interpreter, nothing changes.

I'm guessing if we make this change, we no longer need to disable the GIL in run and presolve via py::call_guard<py::gil_scoped_release>()?

No, that would affect users of all Python versions, so I would not touch that.

@jajhall jajhall merged commit 9567bac into ERGO-Code:latest Nov 27, 2024
104 checks passed
@jajhall
Copy link
Member

jajhall commented Nov 27, 2024

Thanks @mathgeekcoder and @rgommers , I'm happy with this as it is

@rgommers rgommers deleted the nogil-safe-upstream branch November 27, 2024 17:11
@rgommers
Copy link
Contributor Author

Great, thanks for the quick review!

@jajhall
Copy link
Member

jajhall commented Nov 27, 2024

Great, thanks for the quick review!

You're welcome. It should be in the next release of HiGHS, which will come out in a couple of weeks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants